if (!jsx3.lang.Class.forName("ux.cdb.admin.contract.receipt.ReceiptBuilder")) {
/**
 * Define the <code>tibco.spm.design.rule.builder.Builder</code> class.
 * This class inherit from <code>jsx3.gui.Dialog<code> GUI class.
 */
jsx3.Class.defineClass(
        "ux.cdb.admin.contract.receipt.ReceiptBuilder",
        jsx3.gui.Dialog,
        null,
        function (objRoot) {
            /**
             * This method will be called after UI file has deserialized.
             */
            objRoot.prototype.onAfterDeserialize = function() {
                this.wizard = this.get("steppedWizard");
                this.service = ux.cdb.admin.contract.ContractPage.Service;
            };
            
            objRoot.prototype.closeBuilder = function(noConfirm) {
                this.doClose();
            };
            objRoot.prototype.onClose = function() {
                this.unLock();
                this.doClose();
            }
            objRoot.prototype.unLock = function() {
                try{
                    if(this.wizard.newAppBasicInfo.id.appBasicInfoId){
                        ux.megatron.util.Dwr.callDwr("RetailStudentLoanContractFeedBackUCC", "unlockContract", [this.wizard.newAppBasicInfo.id.appBasicInfoId], this, function(dwrObject) {
                            console.log(dwrObject);
                        }, "RetailStudentLoanContractFeedBackUCC");
                    }
                } catch(ex) {
                    console.log(ex);
                }
            };
            objRoot.prototype.saveBuilder = function() {
                var result = false, curr, panel, tip, i, stepOneInfo;
                curr = this.wizard.getCurrentPanel();
                for(i=1; i<=1; i++) {
                    panel = this.get("wizPanel_" + i);
                    if(!panel.loaded || !panel.doValidation()) {
                        tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@contractReceipt@TipUnFinishedStep" + i);
                        this.wizard.getMessageLabel().setText(tip);
                        return;
                    }
                }

                if(ux.megatron.Main.isFileSystem()) {
                    stepOneInfo = this.wizard.stepOneInfo;
                    var info = "Commit Save Date to Server: \n\n";
                    info += "stepOneInfo -> { \n";
                    for(var name in stepOneInfo) {
                        info += name + ":" + stepOneInfo[name] + ", \n"; 
                    }
                    info += "} \n";
/* @JSC :: begin DEBUG */
                    jsx3.log("SAVEINFO:" + info);
/* @JSC :: end */

                    this.closeBuilder();
                } else {
					var extendObj = function(tarObj,orgObj){
						for(var prop in orgObj){
							tarObj[prop] = orgObj[prop];
						}
						return tarObj;
					}

                    stepOneInfo = this.wizard.stepOneInfo;

                    var attrs = ["feedbackYear","feedbackReceiveDate", "studentOweTuitionAmt","studentOweAccommodationAmt"];
                    var _newAppBasicInfo = this.wizard.newAppBasicInfo;
                    for(i=0; i<attrs.length; i++) {
                        _newAppBasicInfo[attrs[i]] = stepOneInfo[attrs[i]];
                    }
                    _newAppBasicInfo.studentOweAccommodationAmt = 0;

                    attrs = [/* "educationSysDesc",  */"collegeName", "className", "enrollDate", "graduateDate"];
                    var _schoolingInfo = this.wizard.schoolingInfo;
                    for(i=0; i<attrs.length; i++) {
                        _schoolingInfo[attrs[i]] = stepOneInfo[attrs[i]];
                    }
                    _schoolingInfo.studentId = _newAppBasicInfo.partyId;

					var _acct = {};
					attrs = ["openAccountBankName", "openAccountBranchName", "openAccountSubBranchName", "openAccountOfficeName", "acctName", "acctNbr"];
					for(i=0; i<attrs.length; i++) {
						_acct[attrs[i]] = stepOneInfo[attrs[i]];
					}
					_acct.partyId = _newAppBasicInfo.schoolId;

/* @JSC :: begin DEBUG */
					jsx3.log('this.wizard.acct A: '+dwr.util.toDescriptiveString(this.wizard.acct,4));
/* @JSC :: end */
					if(this.wizard.acct){
						this.wizard.acct.acctId = parseInt(this.wizard.acct.acctId);
						if(isNaN(this.wizard.acct.acctId)){
							this.wizard.acct.acctId = null;
						}
						extendObj(this.wizard.acct, _acct);
					}else{
						this.wizard.acct = _acct;
					}

                    var _contactPerson = {};
					attrs = ["contactPersonName", "contactPersonFixPhone"];
					for(i=0; i<attrs.length; i++) {
						_contactPerson[attrs[i]] = stepOneInfo[attrs[i]];
					}
					_contactPerson.partyId = _newAppBasicInfo.schoolId;
/* @JSC :: begin DEBUG */
					jsx3.log('this.wizard.contactPerson A: '+dwr.util.toDescriptiveString(this.wizard.contactPerson,4));
/* @JSC :: end */
                    if(this.wizard.contactPerson) {
						this.wizard.contactPerson.contactPersonId = parseInt(this.wizard.contactPerson.contactPersonId);
                        if(isNaN(this.wizard.contactPerson.contactPersonId)){
                            this.wizard.contactPerson.contactPersonId = null;
                        }
						extendObj(this.wizard.contactPerson, _contactPerson);
                    }else{
						this.wizard.contactPerson = _contactPerson;
					}
/* @JSC :: begin DEBUG */
					jsx3.log('this.wizard.acct B: '+dwr.util.toDescriptiveString(this.wizard.acct,4));
/* @JSC :: end */
					//return;

                    this.service.saveReceiptInfo(_newAppBasicInfo, _schoolingInfo, this.wizard.acct, this.wizard.contactPerson, function(){
                        if(this.opener && this.opener.refreshList) {
                            var opener = this.opener;
                            setTimeout(function() {opener.refreshList();}, 10);
                        }
                        var parent = ux.megatron.Main.getServer().getBodyBlock();
                        delete parent.newAppBasicInfo;
                        delete parent.acct;
                        delete parent.contractPerson;
                        delete parent.schoolingInfo;
                        this.closeBuilder(true);
                    }, this);
                }
            };
        });
}